/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class code1 {
    public void reorderList(ListNode head) {

        ListNode head1 = head;
        ListNode head2 = reverse(getMid(head));
        while(head2.next != null) {//核心（偶数注意）一个是【1，2，3】一个是【4.3】
            ListNode headN1 = head1.next;
            ListNode headN2 = head2.next;
            head1.next = head2;
            head2.next = headN1;
            head1 = headN1;
            head2 = headN2;
        }
    }
    private ListNode getMid(ListNode head) {
        ListNode fast = head;
        ListNode slow = head;

        while(fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }
        return slow;
    }
    private ListNode reverse(ListNode head) {
        ListNode prev = null;//1
        ListNode cur = head;
        while(cur != null) {
            ListNode Next = cur.next;
            cur.next = prev;//2
            prev = cur;
            cur = Next;
        }
        return prev;
    }
}